// 导入 express
const express = require('express')
// 创建路由对象
const router = express.Router();
// 导入文章的路由处理函数模块
const articlehandler = require('../router_handler/article');
// 导入验证数据的中间件
const expressJoi = require('@escook/express-joi');
// 导入文章的验证模块
const { add_article_schema ,list_article_schema,del_article_schema,edit_article_schema} = require('../schema/article');
// 发布新文章0
// 导入解析 formdata 格式表单数据的包
const multer = require('multer');
// 导入处理路径的核心模块
const path = require('path');

// 创建 multer 的实例对象，通过 dest 属性指定文件的存放路径
const upload = multer({ dest: path.join(__dirname, '../uploads') });

router.post('/article/add', upload.single('cover_img'), expressJoi(add_article_schema), articlehandler.addart);
// 获取文章列表
router.get('/article/list', expressJoi(list_article_schema), articlehandler.listart);
// 根据id删除文章
router.get('/article/delete/:id', expressJoi(del_article_schema), articlehandler.delart);
// 根据id查询文章
router.get('/article/:id', expressJoi(del_article_schema), articlehandler.selart);

router.post('/article/edit', upload.single('cover_img'), expressJoi(edit_article_schema), articlehandler.editart);
// 向外共享路由对象
module.exports = router
